package org.funtester.performance.books.chapter08.section2;

import com.funtester.fungrpc.QueryRequest;
import com.funtester.fungrpc.QueryResponse;
import com.funtester.fungrpc.UserServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

public class BlockingClient {

    public static void main(String[] args) {
        ManagedChannel managedChannel = ManagedChannelBuilder// 创建连接builder对象
                .forAddress("127.0.0.1", 8080)// 指定地址和端口
                .usePlaintext()// 使用明文传输,不使用ssl安全连接
                .build();// 创建连接

        UserServiceGrpc.UserServiceBlockingStub userServiceBlockingStub = UserServiceGrpc.newBlockingStub(managedChannel);// 创建阻塞stub
        QueryRequest queryRequest = QueryRequest.newBuilder().setId(888).build();// 创建请求对象
        QueryResponse queryResponse = userServiceBlockingStub.queryUser(queryRequest);// 发送请求
        System.out.println(queryResponse.getId());// 打印响应结果用户id
        System.out.println(queryResponse.getName());// 打印响应结果用户名
        System.out.println(queryResponse.getAge());// 打印响应结果用户年龄
        System.out.println(queryResponse.getRegion());// 打印响应结果用户地区
        System.out.println(queryResponse.getAddress());// 打印响应结果用户地址
        managedChannel.shutdown();// 关闭连接
    }

}
